﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using Facade;
using IronOne.SalesOne.BusinessObjects;
using System.Configuration;

namespace IronOne.SalesOne.SalesOneWeb.UserManagement
{
    public partial class CodeType : SOSecurityPage, IDataPage, IntTest
    {
        private int pageNo = 1;

        List<Country> countries;
        List<IDType> idtypes;
        List<InformationType> informationtypes;
        List<MaritalStatus> maritalstatuss;
        List<Measure> measures;
        List<Month> months;
        List<PaymentMode> paymentmodes;
        List<PendingRequirement> pendingrequirements;
        List<PendingStatus> pendingstatuss;
        List<PolicyStatus> policystatuss;
        List<PolicyType> policytypes;
        List<Salutation> salutations;
        List<SOType> sotypes;
        List<ComplaintType> complainttypes;
        List<ComplaintStatus> complaintstatuss;
        List<CompetionType> competiontypes;
        List<CompaintSubType> complaintsubtypes;
        List<ClaimStatus> claimstatuss;

        CodeFacade codeFacede = new CodeFacade();

        int successDel = 0;

        protected void Page_Load(object sender, EventArgs e)
        {
            String codeType = string.Empty;
            String codeTypeUp = string.Empty;


            UCGridButtons1.SetCredentials(ValidateUserCredentials(Request.Url.LocalPath));

            lblUpdateMsg.Text = "";

            if (Session["successCodeUpdate"] != null)
            {
                MassageSummery("IIS402");
                Session.Remove("successCodeUpdate");
            }

            if (Session["failCodeUpdate"] != null)
            {
                MassageSummery("IIS502");
                Session.Remove("failCodeUpdate");
            }

            if (!Page.IsPostBack)
            {
                pageNo = 1;
                UCGrid1.SetText("1");
                if (Request.QueryString["t"] != null)
                {
                    pageNo = 1;
                    codeType = Request.QueryString["t"];
                    SelectCodeTypeTables(codeType, 1);
                    UCGrid1.SetText("1");
                    TypeDropDownList.SelectedValue = codeType;
                }
                if (Request.QueryString["tt"] != null)
                {
                    pageNo = 1;
                    codeTypeUp = Request.QueryString["tt"];
                    SelectCodeTypeTables(codeTypeUp, 1);
                    UCGrid1.SetText("1");
                    TypeDropDownList.SelectedValue = codeTypeUp;
                }
            }
            else
            {

            }

            if (!IsPostBack && (Request.QueryString["tt"] != null))
            {
                this.UCGridButtons1.Visible = true;
                UCGrid1.Visible = true;
                return;
            }

            if (!IsPostBack && (Request.QueryString["t"] != null))
            {
                this.UCGridButtons1.Visible = true;
                UCGrid1.Visible = true;
                return;
            }

            else if (!IsPostBack)
            {
                this.UCGridButtons1.Visible = false;
            }
            else
            {
                this.UCGridButtons1.Visible = true;
                UCGrid1.Visible = true;
            }

        }

        #region IDataPage Members

        public void Create()
        {

            Response.Redirect("~/UserManagement/ManageCodeTypeCreate.aspx?a=c&t=" + (TypeDropDownList.Text), false);

        }

        public void View()
        {

        }

        public void Update()
        {
            if (Session["codeId"] == null)
            {

                Session["codeId"] = ((GridViewRow)Session["firstRow"]).Cells[2].Text;
                Session.Remove("firstRow");
            }

            if (Session["codeId"] != null)
            {
                Response.Redirect("~/UserManagement/ManageCodeTypeCreate.aspx?a=u&tt=" + (TypeDropDownList.Text), false);

            }
            else
            {
                MassageSummery("IIS503");
            }
        }
        public void Delete()
        {
            if (Session["codeId"] == null)
            {

                Session["codeId"] = ((GridViewRow)Session["firstRow"]).Cells[2].Text;
                Session.Remove("firstRow");
            }

            if ((Session["codeId"] != null))
            {
                DeleteCodeTypes();
                if (successDel == 1)
                {
                    UCGrid1.SetText("1");
                }
                SelectCodeTypeTables(TypeDropDownList.Text, 1);
                Session["codeId"] = null;

            }
            else
            {
                MassageSummery("IIS503");
                Session["codeId"] = null;
            }

        }

        public void Cancel()
        {

        }

        #endregion

        private void SelectCodeTypeTables(String codeType, int page)
        {
            codeFacede = new CodeFacade();
            int[] hideColumn = { 1, 2 };

            UCGrid1.styleList = new List<GridViewStyle> {

                new GridViewStyle{
                    ColumnId = "Select",
                    ColumnHeader = "Select",
                    ColumnWidth = 80},
                new GridViewStyle{
                    ColumnId = "Code",
                    ColumnHeader = "Code",
                    ColumnWidth = 120},
                new GridViewStyle{
                    ColumnId = "Description",
                    ColumnHeader = "Description",
                    ColumnWidth = 700}               
                    };

            switch (codeType)
            {
                case "Country":
                    countries = codeFacede.GetCountries("CodeId ASC", page);
                    if (countries.Count == 0)
                    {
                        MassageSummery("IIS504");

                        UCGrid1.Visible = false;
                        (UCGridButtons1.FindControl("btnCreate")).Visible = true;
                        (UCGridButtons1.FindControl("btnCancel")).Visible = false;
                        (UCGridButtons1.FindControl("btnView")).Visible = false;
                        (UCGridButtons1.FindControl("btnUpdate")).Visible = false;
                        (UCGridButtons1.FindControl("btnDelete")).Visible = false;

                    }
                    else
                    {
                        if (countries.Count == Convert.ToInt32(ConfigurationManager.AppSettings["GridCount"]))
                        {
                            UCGrid1.IsLastPage = (codeFacede.GetCountries("CodeId ASC", page + 1)).Count > 0 ? false : true;
                        }
                        UCGrid1.SetDataSource(countries, hideColumn);
                    }

                    break;

                case "Month":
                    months = codeFacede.GetMonths("CodeId ASC", page);
                    if (months.Count == 0)
                    {
                        MassageSummery("IIS504");

                        UCGrid1.Visible = false;
                        (UCGridButtons1.FindControl("btnCreate")).Visible = true;
                        (UCGridButtons1.FindControl("btnCancel")).Visible = false;
                        (UCGridButtons1.FindControl("btnView")).Visible = false;
                        (UCGridButtons1.FindControl("btnUpdate")).Visible = false;
                        (UCGridButtons1.FindControl("btnDelete")).Visible = false;

                    }
                    else
                    {
                        if (months.Count == Convert.ToInt32(ConfigurationManager.AppSettings["GridCount"]))
                        {
                            UCGrid1.IsLastPage = (codeFacede.GetMonths("CodeId ASC", page + 1)).Count > 0 ? false : true;
                        }
                        UCGrid1.SetDataSource(months, hideColumn);
                    }
                    break;

                case "ID Type":
                    idtypes = codeFacede.GetIDTypes("CodeId ASC", page);
                    if (idtypes.Count == 0)
                    {
                        MassageSummery("IIS504");

                        UCGrid1.Visible = false;
                        (UCGridButtons1.FindControl("btnCreate")).Visible = true;
                        (UCGridButtons1.FindControl("btnCancel")).Visible = false;
                        (UCGridButtons1.FindControl("btnView")).Visible = false;
                        (UCGridButtons1.FindControl("btnUpdate")).Visible = false;
                        (UCGridButtons1.FindControl("btnDelete")).Visible = false;

                    }
                    else
                    {
                        if (idtypes.Count == Convert.ToInt32(ConfigurationManager.AppSettings["GridCount"]))
                        {
                            UCGrid1.IsLastPage = (codeFacede.GetIDTypes("CodeId ASC", page + 1)).Count > 0 ? false : true;
                        }
                        UCGrid1.SetDataSource(idtypes, hideColumn);
                    }
                    break;

                case "Claim Status":
                    claimstatuss = codeFacede.GetClaimStatuss("CodeId ASC", page);
                    if (claimstatuss.Count == 0)
                    {
                        MassageSummery("IIS504");

                        UCGrid1.Visible = false;
                        (UCGridButtons1.FindControl("btnCreate")).Visible = true;
                        (UCGridButtons1.FindControl("btnCancel")).Visible = false;
                        (UCGridButtons1.FindControl("btnView")).Visible = false;
                        (UCGridButtons1.FindControl("btnUpdate")).Visible = false;
                        (UCGridButtons1.FindControl("btnDelete")).Visible = false;

                    }
                    else
                    {
                        if (claimstatuss.Count == Convert.ToInt32(ConfigurationManager.AppSettings["GridCount"]))
                        {
                            UCGrid1.IsLastPage = (codeFacede.GetClaimStatuss("CodeId ASC", page + 1)).Count > 0 ? false : true;
                        }
                        UCGrid1.SetDataSource(claimstatuss, hideColumn);
                    }
                    break;

                case "Complaint Sub Type":
                    complaintsubtypes = codeFacede.GetCompaintSubTypes("CodeId ASC", page);
                    if (complaintsubtypes.Count == 0)
                    {
                        MassageSummery("IIS504");

                        UCGrid1.Visible = false;
                        (UCGridButtons1.FindControl("btnCreate")).Visible = true;
                        (UCGridButtons1.FindControl("btnCancel")).Visible = false;
                        (UCGridButtons1.FindControl("btnView")).Visible = false;
                        (UCGridButtons1.FindControl("btnUpdate")).Visible = false;
                        (UCGridButtons1.FindControl("btnDelete")).Visible = false;

                    }
                    else
                    {
                        if (complaintsubtypes.Count == Convert.ToInt32(ConfigurationManager.AppSettings["GridCount"]))
                        {
                            UCGrid1.IsLastPage = (codeFacede.GetCompaintSubTypes("CodeId ASC", page + 1)).Count > 0 ? false : true;
                        }
                        UCGrid1.SetDataSource(complaintsubtypes, hideColumn);
                    }
                    break;

                case "Competition Type":
                    competiontypes = codeFacede.GetCompetionTypes("CodeId ASC", page);
                    if (competiontypes.Count == 0)
                    {
                        MassageSummery("IIS504");

                        UCGrid1.Visible = false;
                        (UCGridButtons1.FindControl("btnCreate")).Visible = true;
                        (UCGridButtons1.FindControl("btnCancel")).Visible = false;
                        (UCGridButtons1.FindControl("btnView")).Visible = false;
                        (UCGridButtons1.FindControl("btnUpdate")).Visible = false;
                        (UCGridButtons1.FindControl("btnDelete")).Visible = false;

                    }
                    else
                    {
                        if (competiontypes.Count == Convert.ToInt32(ConfigurationManager.AppSettings["GridCount"]))
                        {
                            UCGrid1.IsLastPage = (codeFacede.GetCompetionTypes("CodeId ASC", page + 1)).Count > 0 ? false : true;
                        }
                        UCGrid1.SetDataSource(competiontypes, hideColumn);
                    }
                    break;

                case "Complaint Status":
                    complaintstatuss = codeFacede.GetComplaintStatuss("CodeId ASC", page);
                    if (complaintstatuss.Count == 0)
                    {
                        MassageSummery("IIS504");

                        UCGrid1.Visible = false;
                        (UCGridButtons1.FindControl("btnCreate")).Visible = true;
                        (UCGridButtons1.FindControl("btnCancel")).Visible = false;
                        (UCGridButtons1.FindControl("btnView")).Visible = false;
                        (UCGridButtons1.FindControl("btnUpdate")).Visible = false;
                        (UCGridButtons1.FindControl("btnDelete")).Visible = false;

                    }
                    else
                    {
                        if (complaintstatuss.Count == Convert.ToInt32(ConfigurationManager.AppSettings["GridCount"]))
                        {
                            UCGrid1.IsLastPage = (codeFacede.GetComplaintStatuss("CodeId ASC", page + 1)).Count > 0 ? false : true;
                        }
                        UCGrid1.SetDataSource(complaintstatuss, hideColumn);
                    }
                    break;

                case "Complaint Type":
                    complainttypes = codeFacede.GetComplaintTypes("CodeId ASC", page);
                    if (complainttypes.Count == 0)
                    {
                        MassageSummery("IIS504");

                        UCGrid1.Visible = false;
                        (UCGridButtons1.FindControl("btnCreate")).Visible = true;
                        (UCGridButtons1.FindControl("btnCancel")).Visible = false;
                        (UCGridButtons1.FindControl("btnView")).Visible = false;
                        (UCGridButtons1.FindControl("btnUpdate")).Visible = false;
                        (UCGridButtons1.FindControl("btnDelete")).Visible = false;

                    }
                    else
                    {
                        if (complainttypes.Count == Convert.ToInt32(ConfigurationManager.AppSettings["GridCount"]))
                        {
                            UCGrid1.IsLastPage = (codeFacede.GetComplaintTypes("CodeId ASC", page + 1)).Count > 0 ? false : true;
                        }
                        UCGrid1.SetDataSource(complainttypes, hideColumn);
                    }
                    break;

                case "Information Type":
                    informationtypes = codeFacede.GetInformationTypes("CodeId ASC", page);
                    if (informationtypes.Count == 0)
                    {
                        MassageSummery("IIS504");

                        UCGrid1.Visible = false;
                        (UCGridButtons1.FindControl("btnCreate")).Visible = true;
                        (UCGridButtons1.FindControl("btnCancel")).Visible = false;
                        (UCGridButtons1.FindControl("btnView")).Visible = false;
                        (UCGridButtons1.FindControl("btnUpdate")).Visible = false;
                        (UCGridButtons1.FindControl("btnDelete")).Visible = false;

                    }
                    else
                    {
                        if (informationtypes.Count == Convert.ToInt32(ConfigurationManager.AppSettings["GridCount"]))
                        {
                            UCGrid1.IsLastPage = (codeFacede.GetInformationTypes("CodeId ASC", page + 1)).Count > 0 ? false : true;
                        }
                        UCGrid1.SetDataSource(informationtypes, hideColumn);
                    }
                    break;

                case "Marital Status":
                    maritalstatuss = codeFacede.GetMaritalStatuss("CodeId ASC", page);
                    if (maritalstatuss.Count == 0)
                    {

                        MassageSummery("IIS504");

                        UCGrid1.Visible = false;
                        (UCGridButtons1.FindControl("btnCreate")).Visible = true;
                        (UCGridButtons1.FindControl("btnCancel")).Visible = false;
                        (UCGridButtons1.FindControl("btnView")).Visible = false;
                        (UCGridButtons1.FindControl("btnUpdate")).Visible = false;
                        (UCGridButtons1.FindControl("btnDelete")).Visible = false;

                    }
                    else
                    {
                        if (maritalstatuss.Count == Convert.ToInt32(ConfigurationManager.AppSettings["GridCount"]))
                        {
                            UCGrid1.IsLastPage = (codeFacede.GetMaritalStatuss("CodeId ASC", page + 1)).Count > 0 ? false : true;
                        }
                        UCGrid1.SetDataSource(maritalstatuss, hideColumn);
                    }
                    break;

                case "Policy Type":
                    policytypes = codeFacede.GetPolicyTypes("CodeId ASC", page);
                    if (policytypes.Count == 0)
                    {

                        MassageSummery("IIS504");

                        UCGrid1.Visible = false;
                        (UCGridButtons1.FindControl("btnCreate")).Visible = true;
                        (UCGridButtons1.FindControl("btnCancel")).Visible = false;
                        (UCGridButtons1.FindControl("btnView")).Visible = false;
                        (UCGridButtons1.FindControl("btnUpdate")).Visible = false;
                        (UCGridButtons1.FindControl("btnDelete")).Visible = false;

                    }
                    else
                    {
                        if (policytypes.Count == Convert.ToInt32(ConfigurationManager.AppSettings["GridCount"]))
                        {
                            UCGrid1.IsLastPage = (codeFacede.GetPolicyTypes("CodeId ASC", page + 1)).Count > 0 ? false : true;
                        }
                        UCGrid1.SetDataSource(policytypes, hideColumn);
                    }
                    break;

                case "Salutation":
                    salutations = codeFacede.GetSalutations("CodeId ASC", page);
                    if (salutations.Count == 0)
                    {
                        MassageSummery("IIS504");

                        UCGrid1.Visible = false;
                        (UCGridButtons1.FindControl("btnCreate")).Visible = true;
                        (UCGridButtons1.FindControl("btnCancel")).Visible = false;
                        (UCGridButtons1.FindControl("btnView")).Visible = false;
                        (UCGridButtons1.FindControl("btnUpdate")).Visible = false;
                        (UCGridButtons1.FindControl("btnDelete")).Visible = false;

                    }
                    else
                    {
                        if (salutations.Count == Convert.ToInt32(ConfigurationManager.AppSettings["GridCount"]))
                        {
                            UCGrid1.IsLastPage = (codeFacede.GetSalutations("CodeId ASC", page + 1)).Count > 0 ? false : true;
                        }
                        UCGrid1.SetDataSource(salutations, hideColumn);
                    }
                    break;

                case "Measure":
                    measures = codeFacede.GetMeasures("CodeId ASC", page);
                    if (measures.Count == 0)
                    {

                        MassageSummery("IIS504");

                        UCGrid1.Visible = false;
                        (UCGridButtons1.FindControl("btnCreate")).Visible = true;
                        (UCGridButtons1.FindControl("btnCancel")).Visible = false;
                        (UCGridButtons1.FindControl("btnView")).Visible = false;
                        (UCGridButtons1.FindControl("btnUpdate")).Visible = false;
                        (UCGridButtons1.FindControl("btnDelete")).Visible = false;

                    }
                    else
                    {
                        if (measures.Count == Convert.ToInt32(ConfigurationManager.AppSettings["GridCount"]))
                        {
                            UCGrid1.IsLastPage = (codeFacede.GetMeasures("CodeId ASC", page + 1)).Count > 0 ? false : true;
                        }
                        UCGrid1.SetDataSource(measures, hideColumn);
                    }
                    break;

                case "SO Type":
                    sotypes = codeFacede.GetSOTypes("CodeId ASC", page);
                    if (sotypes.Count == 0)
                    {

                        MassageSummery("IIS504");

                        UCGrid1.Visible = false;
                        (UCGridButtons1.FindControl("btnCreate")).Visible = true;
                        (UCGridButtons1.FindControl("btnCancel")).Visible = false;
                        (UCGridButtons1.FindControl("btnView")).Visible = false;
                        (UCGridButtons1.FindControl("btnUpdate")).Visible = false;
                        (UCGridButtons1.FindControl("btnDelete")).Visible = false;

                    }
                    else
                    {
                        if (sotypes.Count == Convert.ToInt32(ConfigurationManager.AppSettings["GridCount"]))
                        {
                            UCGrid1.IsLastPage = (codeFacede.GetSOTypes("CodeId ASC", page + 1)).Count > 0 ? false : true;
                        }
                        UCGrid1.SetDataSource(sotypes, hideColumn);
                    }
                    break;

                case "Payment Mode":
                    paymentmodes = codeFacede.GetPaymentModes("CodeId ASC", page);
                    if (paymentmodes.Count == 0)
                    {

                        MassageSummery("IIS504");

                        UCGrid1.Visible = false;
                        (UCGridButtons1.FindControl("btnCreate")).Visible = true;
                        (UCGridButtons1.FindControl("btnCancel")).Visible = false;
                        (UCGridButtons1.FindControl("btnView")).Visible = false;
                        (UCGridButtons1.FindControl("btnUpdate")).Visible = false;
                        (UCGridButtons1.FindControl("btnDelete")).Visible = false;

                    }
                    else
                    {
                        if (paymentmodes.Count == Convert.ToInt32(ConfigurationManager.AppSettings["GridCount"]))
                        {
                            UCGrid1.IsLastPage = (codeFacede.GetPaymentModes("CodeId ASC", page + 1)).Count > 0 ? false : true;
                        }
                        UCGrid1.SetDataSource(paymentmodes, hideColumn);
                    }
                    break;

                case "Pending Requirement":
                    pendingrequirements = codeFacede.GetPendingRequirements("CodeId ASC", page);
                    if (pendingrequirements.Count == 0)
                    {

                        MassageSummery("IIS504");

                        UCGrid1.Visible = false;
                        (UCGridButtons1.FindControl("btnCreate")).Visible = true;
                        (UCGridButtons1.FindControl("btnCancel")).Visible = false;
                        (UCGridButtons1.FindControl("btnView")).Visible = false;
                        (UCGridButtons1.FindControl("btnUpdate")).Visible = false;
                        (UCGridButtons1.FindControl("btnDelete")).Visible = false;

                    }
                    else
                    {
                        if (pendingrequirements.Count == Convert.ToInt32(ConfigurationManager.AppSettings["GridCount"]))
                        {
                            UCGrid1.IsLastPage = (codeFacede.GetPendingRequirements("CodeId ASC", page + 1)).Count > 0 ? false : true;
                        }
                        UCGrid1.SetDataSource(pendingrequirements, hideColumn);
                    }
                    break;

                case "Pending Status":
                    pendingstatuss = codeFacede.GetPendingStatuss("CodeId ASC", page);
                    if (pendingstatuss.Count == 0)
                    {

                        MassageSummery("IIS504");

                        UCGrid1.Visible = false;
                        (UCGridButtons1.FindControl("btnCreate")).Visible = true;
                        (UCGridButtons1.FindControl("btnCancel")).Visible = false;
                        (UCGridButtons1.FindControl("btnView")).Visible = false;
                        (UCGridButtons1.FindControl("btnUpdate")).Visible = false;
                        (UCGridButtons1.FindControl("btnDelete")).Visible = false;

                    }
                    else
                    {
                        if (pendingstatuss.Count == Convert.ToInt32(ConfigurationManager.AppSettings["GridCount"]))
                        {
                            UCGrid1.IsLastPage = (codeFacede.GetPendingStatuss("CodeId ASC", page + 1)).Count > 0 ? false : true;
                        }
                        UCGrid1.SetDataSource(pendingstatuss, hideColumn);
                    }
                    break;

                case "Policy Status":
                    policystatuss = codeFacede.GetPolicyStatuss("CodeId ASC", page);
                    if (policystatuss.Count == 0)
                    {
                        MassageSummery("IIS504");

                        UCGrid1.Visible = false;
                        (UCGridButtons1.FindControl("btnCreate")).Visible = true;
                        (UCGridButtons1.FindControl("btnCancel")).Visible = false;
                        (UCGridButtons1.FindControl("btnView")).Visible = false;
                        (UCGridButtons1.FindControl("btnUpdate")).Visible = false;
                        (UCGridButtons1.FindControl("btnDelete")).Visible = false;

                    }
                    else
                    {
                        if (policystatuss.Count == Convert.ToInt32(ConfigurationManager.AppSettings["GridCount"]))
                        {
                            UCGrid1.IsLastPage = (codeFacede.GetPolicyStatuss("CodeId ASC", page + 1)).Count > 0 ? false : true;
                        }
                        UCGrid1.SetDataSource(policystatuss, hideColumn);
                    }
                    break;

                case "Select...":
                    Response.Redirect("~/UserManagement/CodeType.aspx", false);
                    break;

                default:
                    break;
            }

        }


        private void DeleteCodeTypes()
        {
            if (Session["codeId"] == null)
            {
                Session["codeId"] = ((GridViewRow)Session["firstRow"]).Cells[2].Text;
                Session.Remove("firstRow");
            }


            switch (TypeDropDownList.Text)
            {
                case "Country":
                    try
                    {
                        String codeType = Session["codeId"].ToString();
                        int codeID = int.Parse(codeType);


                        Country country = new Country();
                        CodeFacade objFacade = new CodeFacade();
                        country = objFacade.GetCountry(codeID);
                        successDel = objFacade.DeleteCodeCountry(country);


                        //Country country = new Country();
                        //country = countries.Find(GetCountry);
                        //CodeFacade objFacade = new CodeFacade();
                        //successDel = objFacade.DeleteCodeCountry(country);

                        if (successDel == 1)
                        {
                            //pageNo = 1;
                            MassageSummery("IIS403");
                            //pageNo = 1;
                        }
                        else
                        {
                            MassageSummery("IIS502");

                        }
                    }
                    catch (Exception ex)
                    {
                    }
                    break;


                case "Month":
                    try
                    {
                        String codeType = Session["codeId"].ToString();
                        int codeID = int.Parse(codeType);

                        Month codeMonthObject = new Month();
                        CodeFacade objFacade = new CodeFacade();
                        codeMonthObject = objFacade.GetMonth(codeID);
                        successDel = objFacade.DeleteCodeMonth(codeMonthObject);

                        if (successDel == 1)
                        {
                            MassageSummery("IIS403");
                        }
                        else
                        {
                            MassageSummery("IIS502");
                        }

                    }
                    catch (Exception ex)
                    {
                    }
                    break;


                case "Claim Status":
                    try
                    {
                        String codeType = Session["codeId"].ToString();
                        int codeID = int.Parse(codeType);

                        ClaimStatus codeClaimStatusObject = new ClaimStatus();
                        CodeFacade objFacade = new CodeFacade();
                        codeClaimStatusObject = objFacade.GetClaimStatus(codeID);
                        successDel = objFacade.DeleteCodeClaimStatus(codeClaimStatusObject);

                        if (successDel == 1)
                        {
                            MassageSummery("IIS403");
                        }
                        else
                        {
                            MassageSummery("IIS502");
                        }

                    }
                    catch (Exception ex)
                    {
                    }
                    break;


                case "Complaint Sub Type":
                    try
                    {
                        String codeType = Session["codeId"].ToString();
                        int codeID = int.Parse(codeType);

                        CompaintSubType codeCompaintSubTypeObject = new CompaintSubType();
                        CodeFacade objFacade = new CodeFacade();
                        codeCompaintSubTypeObject = objFacade.GetCompaintSubType(codeID);
                        successDel = objFacade.DeleteCodeCompaintSubType(codeCompaintSubTypeObject);

                        if (successDel == 1)
                        {
                            MassageSummery("IIS403");
                        }
                        else
                        {
                            MassageSummery("IIS502");
                        }

                    }
                    catch (Exception ex)
                    {
                    }
                    break;

                case "Competition Type":
                    try
                    {
                        String codeType = Session["codeId"].ToString();
                        int codeID = int.Parse(codeType);

                        CompetionType codeCompetionTypeObject = new CompetionType();
                        CodeFacade objFacade = new CodeFacade();
                        codeCompetionTypeObject = objFacade.GetCompetionType(codeID);
                        successDel = objFacade.DeleteCodeCompetionType(codeCompetionTypeObject);

                        if (successDel == 1)
                        {
                            MassageSummery("IIS403");
                        }
                        else
                        {
                            MassageSummery("IIS502");
                        }

                    }
                    catch (Exception ex)
                    {
                    }
                    break;


                case "Complaint Status":
                    try
                    {
                        String codeType = Session["codeId"].ToString();
                        int codeID = int.Parse(codeType);

                        ComplaintStatus codeComplaintStatusObject = new ComplaintStatus();
                        CodeFacade objFacade = new CodeFacade();
                        codeComplaintStatusObject = objFacade.GetComplaintStatus(codeID);
                        successDel = objFacade.DeleteCodeComplaintStatus(codeComplaintStatusObject);

                        if (successDel == 1)
                        {
                            MassageSummery("IIS403");
                        }
                        else
                        {
                            MassageSummery("IIS502");
                        }

                    }
                    catch (Exception ex)
                    {
                    }
                    break;



                case "Complaint Type":
                    try
                    {
                        String codeType = Session["codeId"].ToString();
                        int codeID = int.Parse(codeType);

                        ComplaintType codeComplaintTypeObject = new ComplaintType();
                        CodeFacade objFacade = new CodeFacade();
                        codeComplaintTypeObject = objFacade.GetComplaintType(codeID);
                        successDel = objFacade.DeleteCodeComplaintType(codeComplaintTypeObject);

                        if (successDel == 1)
                        {
                            MassageSummery("IIS403");
                        }
                        else
                        {
                            MassageSummery("IIS502");
                        }

                    }
                    catch (Exception ex)
                    {
                    }
                    break;


                case "ID Type":
                    try
                    {
                        String codeType = Session["codeId"].ToString();
                        int codeID = int.Parse(codeType);

                        IDType codeIDTypeObject = new IDType();
                        CodeFacade objFacade = new CodeFacade();
                        codeIDTypeObject = objFacade.GetIDType(codeID);
                        successDel = objFacade.DeleteCodeIDType(codeIDTypeObject);

                        if (successDel == 1)
                        {
                            MassageSummery("IIS403");
                        }
                        else
                        {
                            MassageSummery("IIS502");
                        }

                    }
                    catch (Exception ex)
                    {
                    }
                    break;


                case "Information Type":
                    try
                    {
                        String codeType = Session["codeId"].ToString();
                        int codeID = int.Parse(codeType);

                        InformationType codeInformationTypeObject = new InformationType();
                        CodeFacade objFacade = new CodeFacade();
                        codeInformationTypeObject = objFacade.GetInformationType(codeID);
                        successDel = objFacade.DeleteCodeInformationType(codeInformationTypeObject);

                        if (successDel == 1)
                        {
                            MassageSummery("IIS403");
                        }
                        else
                        {
                            MassageSummery("IIS502");
                        }

                    }
                    catch (Exception ex)
                    {
                    }
                    break;


                case "Marital Status":
                    try
                    {
                        String codeType = Session["codeId"].ToString();
                        int codeID = int.Parse(codeType);

                        MaritalStatus codeMaritalStatusObject = new MaritalStatus();
                        CodeFacade objFacade = new CodeFacade();
                        codeMaritalStatusObject = objFacade.GetMaritalStatus(codeID);
                        successDel = objFacade.DeleteCodeMaritalStatus(codeMaritalStatusObject);

                        if (successDel == 1)
                        {
                            MassageSummery("IIS403");
                        }
                        else
                        {
                            MassageSummery("IIS502");
                        }

                    }
                    catch (Exception ex)
                    {
                    }
                    break;


                case "Policy Type":
                    try
                    {
                        String codeType = Session["codeId"].ToString();
                        int codeID = int.Parse(codeType);

                        PolicyType codePolicyTypeObject = new PolicyType();
                        CodeFacade objFacade = new CodeFacade();
                        codePolicyTypeObject = objFacade.GetPolicyType(codeID);
                        successDel = objFacade.DeleteCodePolicyType(codePolicyTypeObject);

                        if (successDel == 1)
                        {
                            MassageSummery("IIS403");
                        }
                        else
                        {
                            MassageSummery("IIS502");
                        }

                    }
                    catch (Exception ex)
                    {
                    }
                    break;


                case "Policy Status":
                    try
                    {
                        String codeType = Session["codeId"].ToString();
                        int codeID = int.Parse(codeType);

                        PolicyStatus codePolicyStatusObject = new PolicyStatus();
                        CodeFacade objFacade = new CodeFacade();
                        codePolicyStatusObject = objFacade.GetPolicyStatus(codeID);
                        successDel = objFacade.DeleteCodePolicyStatus(codePolicyStatusObject);

                        if (successDel == 1)
                        {
                            MassageSummery("IIS403");
                        }
                        else
                        {
                            MassageSummery("IIS502");
                        }

                    }
                    catch (Exception ex)
                    {
                    }
                    break;

                case "Salutation":
                    try
                    {
                        String codeType = Session["codeId"].ToString();
                        int codeID = int.Parse(codeType);

                        Salutation codeSalutationObject = new Salutation();
                        CodeFacade objFacade = new CodeFacade();
                        codeSalutationObject = objFacade.GetSalutation(codeID);
                        successDel = objFacade.DeleteCodeSalutation(codeSalutationObject);

                        if (successDel == 1)
                        {
                            MassageSummery("IIS403");
                        }
                        else
                        {
                            MassageSummery("IIS502");
                        }

                    }
                    catch (Exception ex)
                    {
                    }
                    break;


                case "Measure":
                    try
                    {
                        String codeType = Session["codeId"].ToString();
                        int codeID = int.Parse(codeType);

                        Measure codeMeasureObject = new Measure();
                        CodeFacade objFacade = new CodeFacade();
                        codeMeasureObject = objFacade.GetMeasure(codeID);
                        successDel = objFacade.DeleteCodeMeasure(codeMeasureObject);

                        if (successDel == 1)
                        {
                            MassageSummery("IIS403");
                        }
                        else
                        {
                            MassageSummery("IIS502");
                        }

                    }
                    catch (Exception ex)
                    {
                    }
                    break;


                case "SO Type":
                    try
                    {
                        String codeType = Session["codeId"].ToString();
                        int codeID = int.Parse(codeType);

                        SOType codeSOTypeObject = new SOType();
                        CodeFacade objFacade = new CodeFacade();
                        codeSOTypeObject = objFacade.GetSOType(codeID);
                        successDel = objFacade.DeleteCodeSOType(codeSOTypeObject);

                        if (successDel == 1)
                        {
                            MassageSummery("IIS403");
                        }
                        else
                        {
                            MassageSummery("IIS502");
                        }

                    }
                    catch (Exception ex)
                    {
                    }
                    break;


                case "Payment Mode":
                    try
                    {
                        String codeType = Session["codeId"].ToString();
                        int codeID = int.Parse(codeType);

                        PaymentMode codePaymentModeObject = new PaymentMode();
                        CodeFacade objFacade = new CodeFacade();
                        codePaymentModeObject = objFacade.GetPaymentMode(codeID);
                        successDel = objFacade.DeleteCodePaymentMode(codePaymentModeObject);

                        if (successDel == 1)
                        {
                            MassageSummery("IIS403");
                        }
                        else
                        {
                            MassageSummery("IIS502");
                        }

                    }
                    catch (Exception ex)
                    {
                    }
                    break;


                case "Pending Requirement":
                    try
                    {
                        String codeType = Session["codeId"].ToString();
                        int codeID = int.Parse(codeType);

                        PendingRequirement codePendingRequirementObject = new PendingRequirement();
                        CodeFacade objFacade = new CodeFacade();
                        codePendingRequirementObject = objFacade.GetPendingRequirement(codeID);
                        successDel = objFacade.DeleteCodePendingRequirement(codePendingRequirementObject);

                        if (successDel == 1)
                        {
                            MassageSummery("IIS403");
                        }
                        else
                        {
                            MassageSummery("IIS502");
                        }

                    }
                    catch (Exception ex)
                    {
                    }
                    break;

                case "Pending Status":
                    try
                    {
                        String codeType = Session["codeId"].ToString();
                        int codeID = int.Parse(codeType);

                        PendingStatus codePendingStatusObject = new PendingStatus();
                        CodeFacade objFacade = new CodeFacade();
                        codePendingStatusObject = objFacade.GetPendingStatus(codeID);
                        successDel = objFacade.DeleteCodePendingStatus(codePendingStatusObject);

                        if (successDel == 1)
                        {
                            MassageSummery("IIS403");
                        }
                        else
                        {
                            MassageSummery("IIS502");
                        }

                    }
                    catch (Exception ex)
                    {
                    }
                    break;

                default:
                    break;


            }


        }

        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            UCGrid1.SetText("1");
            Session["selectValue"] = TypeDropDownList.SelectedValue;
            String type = TypeDropDownList.Text;
            SelectCodeTypeTables(type, pageNo);
            pageNo = 1;
            UCGrid1.SetText("1");


        }

        protected void TypeDropDownList_TextChanged(object sender, EventArgs e)
        {

        }

        protected void CreateButton_Click(object sender, EventArgs e)
        {


        }

        protected void DeleteButton_Click(object sender, EventArgs e)
        {


        }



        #region IDataPage Members - rbn session


        public void GetId(GridViewRow row)
        {
            Session["codeId"] = row.Cells[2].Text;
        }

        #endregion


        #region IDataPage Members - Paging


        public void Next()
        {
            if (UCGrid1.GetText() != "1")
            {
                pageNo = Convert.ToInt32(UCGrid1.GetText()) + 1;
                UCGrid1.SetText(pageNo.ToString());

            }
            else
            {
                pageNo = 2;
                UCGrid1.SetText("2");

            }

            SelectCodeTypeTables((TypeDropDownList.SelectedValue), pageNo);
        }

        public void Previous()
        {
            if (UCGrid1.GetText() != "1")
            {
                pageNo = Convert.ToInt32(UCGrid1.GetText()) - 1;
                UCGrid1.SetText(pageNo.ToString());

                SelectCodeTypeTables((TypeDropDownList.SelectedValue), pageNo);
            }
        }

        public void Go()
        {
            int p = int.Parse(UCGrid1.GetText());
            if (p != 0)
            {
                try
                {
                    SelectCodeTypeTables((TypeDropDownList.SelectedValue), p);
                    pageNo = p;
                }
                catch (Exception)
                {

                    throw;
                }


            }


        }

        #endregion


    }
}
